Imports System.Web
Imports System.Text

Public Class Rpt_Tables
    Private Const Q As String = Chr(34)

    Public Sub ShowTableList( _
                    ByVal lDatabaseID As Long, _
                    ByVal lRevID As Long, _
                    Optional ByVal lSort As Table_Factory.SORT = Table_Factory.SORT.NAME_ASC)

        Dim oDatabase As New SQLAutoDocLib.Database(lDatabaseID, lRevID)
        oDatabase.Load()

        Dim sURL As String = "SQTableE.aspx?S=" & oDatabase.ServerID & "&D=" & lDatabaseID & "&SORT="

        Dim sHTM As New StringBuilder

        sHTM.Append("<table class=" & Q & "wmObjectList_T" & Q & Q & ">")

        sHTM.Append("<tr class=" & Q & "wmObjectList_TH" & Q & " style=" & Q & "height: 39px; background-color: #C3C4C1; border-bottom: solid 1px black;" & Q & ">")

        sHTM.Append("<td class=" & Q & "wmObjectList_ZC" & Q & ">")
        sHTM.Append("&nbsp;")
        sHTM.Append("</td>")

        sHTM.Append("<td class=" & Q & "wmObjectList_ZM" & Q & ">")
        sHTM.Append("<span style=" & Q & "white-space: nowrap;" & Q & ">")

        If lSort <> SQLAutoDocLib.SProc_Factory.SORT.DATE_ASC Then
            sHTM.Append("<a href=" & Q & sURL & SQLAutoDocLib.SProc_Factory.SORT.DATE_ASC & Q & ">")
            sHTM.Append("<img src=" & Q & "images/arrow_up.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Ascending Order by Date" & Q & _
                         " title=" & Q & "Ascending Order by Date" & Q & _
                         "/>")
            sHTM.Append("</a>")
        Else
            sHTM.Append("<img src=" & Q & "images/action_up.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Ascending Order by Date" & Q & _
                         " title=" & Q & "Ascending Order by Date" & Q & _
                         "/>")
        End If

        If lSort <> SQLAutoDocLib.SProc_Factory.SORT.DATE_DESC Then
            sHTM.Append("<a href=" & Q & sURL & SQLAutoDocLib.SProc_Factory.SORT.DATE_DESC & Q & ">")
            sHTM.Append("<img src=" & Q & "images/arrow_dn.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Descending Order by Date" & Q & _
                         " title=" & Q & "Descending Order by Date" & Q & _
                         "/>")
            sHTM.Append("</a>")
        Else
            sHTM.Append("<img src=" & Q & "images/action_dn.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Descending Order by Date" & Q & _
                         " title=" & Q & "Descending Order by Date" & Q & _
                         "/>")
        End If

        sHTM.Append("Modified")
        sHTM.Append("</span>")
        sHTM.Append("</td>")

        sHTM.Append("<td class=" & Q & "wmObjectList_ZR" & Q & ">")
        sHTM.Append("<span style=" & Q & "white-space: nowrap;" & Q & ">")
        If lSort <> SQLAutoDocLib.SProc_Factory.SORT.VER_ASC Then
            sHTM.Append("<a href=" & Q & sURL & SQLAutoDocLib.SProc_Factory.SORT.VER_ASC & Q & ">")
            sHTM.Append("<img src=" & Q & "images/arrow_up.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Ascending Order by Revision" & Q & _
                         " title=" & Q & "Ascending Order by Revision" & Q & _
                         "/>")
            sHTM.Append("</a>")
        Else
            sHTM.Append("<img src=" & Q & "images/action_up.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Ascending Order by Revision" & Q & _
                         " title=" & Q & "Ascending Order by Revision" & Q & _
                         "/>")
        End If

        If lSort <> SQLAutoDocLib.SProc_Factory.SORT.VER_DESC Then
            sHTM.Append("<a href=" & Q & sURL & SQLAutoDocLib.SProc_Factory.SORT.VER_DESC & Q & ">")
            sHTM.Append("<img src=" & Q & "images/arrow_dn.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Descending Order by Revision" & Q & _
                         " title=" & Q & "Descending Order by Revision" & Q & _
                         "/>")
            sHTM.Append("</a>")
        Else
            sHTM.Append("<img src=" & Q & "images/action_dn.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Descending Order by Revision" & Q & _
                         " title=" & Q & "Descending Order by Revision" & Q & _
                         "/>")
        End If
        sHTM.Append("Rev")
        sHTM.Append("</span>")
        sHTM.Append("</td>")

        sHTM.Append("<td class=" & Q & "wmObjectList_ZN" & Q & ">")
        sHTM.Append("<span style=" & Q & "white-space: nowrap;" & Q & ">")
        If lSort <> SQLAutoDocLib.SProc_Factory.SORT.NAME_ASC Then
            sHTM.Append("<a href=" & Q & sURL & SQLAutoDocLib.SProc_Factory.SORT.NAME_ASC & Q & ">")
            sHTM.Append("<img src=" & Q & "images/arrow_up.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Ascending Order by Name" & Q & _
                         " title=" & Q & "Ascending Order by Name" & Q & _
                         "/>")
            sHTM.Append("</a>")
        Else
            sHTM.Append("<img src=" & Q & "images/action_up.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Ascending Order by Name" & Q & _
                         " title=" & Q & "Ascending Order by Name" & Q & _
                         "/>")
        End If

        If lSort <> SQLAutoDocLib.SProc_Factory.SORT.NAME_DESC Then
            sHTM.Append("<a href=" & Q & sURL & SQLAutoDocLib.SProc_Factory.SORT.NAME_DESC & Q & ">")
            sHTM.Append("<img src=" & Q & "images/arrow_dn.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Descending Order by Name" & Q & _
                         " title=" & Q & "Descending Order by Name" & Q & _
                         "/>")
            sHTM.Append("</a>")
        Else
            sHTM.Append("<img src=" & Q & "images/action_dn.gif" & Q & _
                         " border=" & Q & "0" & Q & _
                         " alt=" & Q & "Descending Order by Name" & Q & _
                         " title=" & Q & "Descending Order by Name" & Q & _
                         "/>")
        End If
        sHTM.Append("Name")
        sHTM.Append("</span>")
        sHTM.Append("</td>")

        sHTM.Append("</tr>")

        Dim oList As New ArrayList

        Dim bAlternatingRow As Boolean = False

        Dim oFactory As New SQLAutoDocLib.Table_Factory
        For Each oTable As SQLAutoDocLib.Table In oFactory.GetAllTablesForDatabase(lDatabaseID, lRevID, lSort)
            If bAlternatingRow = False Then
                sHTM.Append("<tr class=" & Q & "wmObjectList_T" & Q & ">")
            Else
                sHTM.Append("<tr class=" & Q & "wmObjectList_TA" & Q & ">")
            End If

            sHTM.Append("<td>")
            sHTM.Append("<a href=" & Q & "SQTableD.aspx?S=" & oDatabase.ServerID & "&D=" & lDatabaseID & "&O=" & oTable.ID & Q & ">")
            sHTM.Append("<img src=" & Q & "images/help.gif" & Q & " border=0/>")
            sHTM.Append("</a>")

            sHTM.Append("</td>")

            sHTM.Append("<td>")
            sHTM.Append(oTable.LastModified)
            sHTM.Append("</td>")

            sHTM.Append("<td>")
            sHTM.Append(oTable.RevID)
            sHTM.Append("</td>")

            sHTM.Append("<td>")
            sHTM.Append(oTable.Name)
            sHTM.Append("</td>")

            sHTM.Append("</tr>")

            If oTable.Desc.Length > 0 Then
                If bAlternatingRow = False Then
                    sHTM.Append("<tr class=" & Q & "wmObjectList_T" & Q & ">")
                Else
                    sHTM.Append("<tr class=" & Q & "wmObjectList_TA" & Q & ">")
                End If

                sHTM.Append("<td>")
                sHTM.Append("&nbsp;")
                sHTM.Append("</td>")

                sHTM.Append("<td>")
                sHTM.Append("&nbsp;")
                sHTM.Append("</td>")

                sHTM.Append("<td colspan=" & Q & "2" & Q & ">")
                sHTM.Append(oTable.Desc)
                sHTM.Append("</td>")

                sHTM.Append("</tr>")
            End If

            bAlternatingRow = Not bAlternatingRow
        Next

        sHTM.Append("</table>")

        HttpContext.Current.Response.Write(sHTM.ToString)
    End Sub

End Class
